<template>
	<view>
		<u-sticky bgColor="#fff">
			<view class="help-pubuBox">
				<u-search placeholder="搜索厂家名称" :clearabled="true" v-model="title" @change="change" @search="chaxun"
					@custom="chaxun" :showAction="false" height="40" shape="square" color="#2B2B2B"></u-search>
			</view>
		</u-sticky>
		<view class="add-cj" @click="addFactory">
			+新增厂家
		</view>
		<u-gap height="8" bgColor="#f2f2f2"></u-gap>
		<view class="cj-item detail-title-border " :class="[itemInfo.id==item.id?'active':'']" v-for="(item,index) in factoryList"
			:key="index" @click="selectPage(item)">
			{{item.factoryName}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: "",
				// actionStyle: {
				// 	color: '#fff',
				// 	background: '#0F53AC',
				// 	padding: '10rpx',
				// 	borderRadius: '8rpx'
				// },
				factoryList: [],
				itemInfo: {},
				params: {
					pn: 1,
					ps: 10,
					factoryType: '',
					keyword: ''
				}
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			change(v) {
				this.title = v
				this.params.pn = 1;
				this.params.keyword = this.title;
				this.getList();
			},
			chaxun() {
				this.params.pn = 1;
				this.params.keyword = this.title;
				this.getList();
			},
			getList() {
				uni.$u.http.post(`/device/mobile/devicePurveyor/purveyorListByPage`, this.params).then(res => {
					if (res.code == 0) {
						this.factoryList = res.data.records;
					}
				}).catch(err => {})
			},
			//新增厂家去到新的页面
			addFactory() {
				uni.navigateTo({
					url: '/pages/subPackagesC/addFactory/addFactory'
				})
			},
			selectPage(item) {
				this.itemInfo = item
				uni.$emit('factoryItem', item);
				setTimeout(() => {
					uni.navigateBack({
						delta: 1
					})
				}, 500)
			}
		}
	}
</script>

<style>
	page {
		background: #FFFFFF;
	}

	.help-pubuBox {
		padding: 22rpx;
		background: #fff;
	}

	.add-cj {
		padding: 20rpx;
	}

	.cj-item {
		padding: 20rpx;
		margin-top: 10rpx;
		background: #fff;
	}

	.active {
		/* background: #0F53AC; */
		color: #2b2b2b;
	}
</style>
